package Controllers

//  日志写入
import (
	"github.com/gin-gonic/gin"
	"net/http"
	_ "net/http"
	"yz-go/Common"
	"yz-go/Logic"
)

type UserInfo struct {
	UserName string `form:"username" json:"username" binding:"required"`
	Password string `form:"password" json:"password" binding:"required,min=6,max=20"`
}

func Login(c *gin.Context) {
	var user UserInfo

	uErr := c.ShouldBind(&user)

	if uErr != nil {
		log := Common.Logger{Status: 200, Msg: "登录测试", Data: user}

		LoggerFileSet(log)

		c.JSON(http.StatusOK, gin.H{
			"code": 2001,
			"msg":  "无效的参数",
		})
		return
	}

	var res Common.ResData

	res = Logic.HandleToken(c.Query("username"), c.Query("password"))

	if res.Code == Common.SUCCESS {
		c.JSON(http.StatusOK, gin.H{
			"code": Common.SUCCESS,
			"msg":  "success",
			"data": res.Data,
		})
		return
	}

}
